#include "headfiles.h"

using namespace std;

bool calcMaxSubArray(int *array, int size, int &max_val, int &start, int &end) {
    if (array == NULL ||
        size <= 0) {
        cout << "Invalid input argument!" << endl;
        return false;
    }

    int max_sum = array[0];
    start = 0;
    end = 1;

    int max_cur_sum = array[0];
    int i, tmp_start = 0;
    for (i = 1; i < size; i++) {
        max_cur_sum += array[i];
        if (max_cur_sum < array[i]) {
            tmp_start = i;
            max_cur_sum = array[i];
        }

        if (max_sum < max_cur_sum) {
            max_sum = max_cur_sum;
            start = tmp_start;
            end = i;
        }
    }

    max_val = max_sum;

    return true;
}

